package com.glela.common.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import tk.mybatis.mapper.common.Mapper;

import com.glela.common.dao.IBaseDao;

/**
 * @author liujie
 * @date 2016年3月4日
 *
 */
@Repository
public class BaseDao<T> implements IBaseDao<T> {

	protected Mapper<T> mapper;

	public Mapper<T> getMapper() {
		return mapper;
	}
	
	public void setMapper(Mapper<T> mapper)
	{
		if(this.mapper==null)
		{
			this.mapper=mapper;
		}
	}

	@Override
	public T queryByKey(Object key) {
		return mapper.selectByPrimaryKey(key);
	}

	public int save(T entity) {
		return mapper.insert(entity);
	}

	public int remove(Object key) {
		return mapper.deleteByPrimaryKey(key);
	}

	public int updateAll(T entity) {
		return mapper.updateByPrimaryKey(entity);
	}

	public int updateNotNull(T entity) {
		return mapper.updateByPrimaryKeySelective(entity);
	}

	public List<T> queryByExample(Object example) {
		return mapper.selectByExample(example);
	}

}
